package com.zzkrst.modules.generator;


import cn.hutool.core.io.IoUtil;
import com.zzkrst.modules.generator.model.GeneratorParam;
import com.zzkrst.modules.generator.utils.GenUtils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipOutputStream;

/**
 * 代码生成器的本地运行，不用启动项目，直接run运行
 */
public class CodeGeneratorMain {

    public static void main(String[] args) throws IOException {
        GeneratorParam param = new GeneratorParam();
        param.setPackageName("com.zzkrst.modules");//包名
        param.setTableName("el_knowledge_file");//表名，必填
        param.setTableComment("课件表-知识库附件表");//表注释，必填        param.setAuthor("SWC");//作者
        param.setToPath("zzkrst-cloud-module-business/zzkrst-cloud-module-class");//生成到项目里的哪个模块
        param.setTablePrefix("el_");//表名前缀。如：表名 tb_delivery_plan_copy ,第二个参数传入 tb_ ,生成的结果为 deliveryPlanCopy,不需要去除前缀可以注释掉

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ZipOutputStream zip = new ZipOutputStream(outputStream);
        //查询列信息

        String url = "jdbc:mysql://116.255.207.241:4417/train_test";
        String mysqlusername = "root";
        String password = "qzgl2020@jc"; // qzgl2020@jc  hnjc@2019@
        List<Map<String, String>> columns = GenUtils.queryColumns(param.getTableName(),url,mysqlusername,password);
        //生成代码
        GenUtils.generatorCode(zip, columns, param);

        IoUtil.close(zip);
    }
}
